import { Component, OnInit } from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router'
import axios from 'axios';

@Component({
  selector: 'app-discussion',
  templateUrl: './discussion.component.html',
  styleUrls: ['./discussion.component.css']
})
export class DiscussionComponent implements OnInit {
  user;
  constructor(private route: ActivatedRoute, private router: Router) {
    this.getCurrentUser();
  }

  ngOnInit(): void {
  }
  public getCurrentUser(){
    let baseUrl = "http://localhost:8999";

    axios.get(baseUrl+'/user/getCurrentUser', {withCredentials: true}).then(res=>{

      this.user = res.data;
      if(!this.user){
        this.router.navigate(['/login']);
      }
      console.log(res)
      //this.isDataLoaded =true
    }).catch((err)=>{
      console.log(err);
    }).finally(()=>{
      console.log('执行完了');
    });
  }


}
